#!/bin/bash
########################################################################
# script name:  reload_autofs.sh
# Used for:
# Author:       Martin Dumont
# Contributors:
# Version:      0.1
#
# (date format: date +'%Y/%m/%d')
#
# Date          Version Contributors    Modifications
# ----------    ------- ------------    -------------
# 2012/02/02    0.1     MDUMONT         initial
########################################################################
usage()
{
cat << STOP

usage: $0 [options] [ARG]

This script is used for ....

OPTIONS:
   -h               All hosts (detail output)

Ex.:
$0 -h non_prd
$0 -h saprmt02
STOP
}
#######################################
# Get parameters
#######################################
while getopts h:s: OPTION
do
        case $OPTION in
        h)
                HOSTS=$(echo $OPTARG | tr '[A-Z]' '[a-z]' | sed 's/,/ /g')
                ;;
        \?)
                usage
                exit 1
                ;;
        *)
                usage
                exit 1
                ;;
        esac
done
if [ $OPTIND = 1 ]; then usage; exit 1; fi
if [ -z "$HOSTS" ]; then echo "Specify a host..."; usage; exit 1; fi
#######################################
# Variables and environnement
#######################################
SSH_OPTS=" -x -o ConnectTimeout=15 -o BatchMode=yes -o StrictHostKeyChecking=no -o LogLevel=quiet"
BAENV=$(dirname `which $0`)/loadenv.sh
if [ -f $BAENV ]; then . $BAENV; else echo "No env library ($BAENV)"; exit 1; fi
NEWHOSTLIST=$(checkhost $HOSTS | grep -v Verifying)
#######################################
# MAIN
#######################################
for HOSTNAME in $NEWHOSTLIST
do
	cat <<-'EOF' | if [ "$HOSTNAME" != "localhost" ]; then sudo -u saunix ssh $SSH_OPTS $HOSTNAME "cat | sudo bash"; else cd /tmp; cat | sudo bash; fi
	if ! sudo /usr/sbin/automount
	then
		echo "ERROR: `uname -n`: something didn't worked, please verify"
	else
		echo "`uname -n` ok"
	fi
EOF
done
#######################################
exit 0
